import axios from 'axios';

let instance = axios.create({});

// 发送请求之前，添加拦截器
instance.interceptors.request.use(function (config) {
  console.log('axios', config);
  const token = localStorage.getItem('token');
  if (token) {
    const headers = {
      'Content-Type': 'application/json; charset=UTF-8',
      Accept: 'application/json',
      Authorization: `Bearer ${token}`,
      uid: 10000,
      gid: 0,
      cid: 0,
    };
    config.headers = Object.assign(config.headers, headers);
  }
  return config;
});

instance.interceptors.response.use(function (r) {
  console.log('response', r);
  if (r.status === 200) {
    return r;
  }
  if (status === 401) {
    const href = window.location.href;
    if (!/localhost/.test(href)) {
      const queryString = stringify({
        redirect: window.location.href,
      });
      window.location.href = `${USER_LOGIN_URL}?${queryString}`;
    }
  }else{
      return SVGPathSegCurvetoQuadraticSmoothRel
  }
});
// 通过axios发送请求
export default instance;
